<?php
	if (eregi("aboutus.php",$_SERVER['PHP_SELF'])) {	
		die("&nbsp;");
	}
	$template_detail_page 	= 'template/about_detail.tpl';
	$template_body_page 	= 'template/about_list.tpl';
	
	$mode = isset($_GET["mode"]) ? htmlspecialchars($_GET["mode"]) : '';
	//$ses_login = $_SESSION['ses_login'];
	
	//tri: variant $cabout in supplier.php - field aboutInfo is NULL
	switch ($mode){	 
		case "view":
			if($cabout == 0) main();
			else ViewDetail();
			break; 
		default:
			main();
	}
//========================================================================================================//
 
function main(){

	global $template, $base_url, $template_body_page,$db,$cid,$ids;	
	
	$memid=isset($_GET["supplier"]) ? intval($_GET["supplier"]) : 0 ;
	
	//tri: Trang templates: about_list.tpl,chinh canh trai 
	//$sql="select sImages,ProductName,proID,catID from vb_products where setHome=1 and memID=".$memid." limit 4";
	$sql="select sImages,ProductName,proID,catID from vb_products where setHome=1 and memID=".$memid." limit 6";
	//echo $sql ; die() ;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	 
	for($i=0;$i<$pro_count;$i++){
		$template->assign_block_vars("proRow", array(
		 'proLink'	=>'supplier.php?supplier='.$memid.'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"]."&catID=".$pro_data[$i]["catID"]."&ids=".$ids."&lang=us",
		 'proImage'	=>'<img src="products/'.$pro_data[$i]["sImages"].'" border="0" class="imageborder">',
		 'proName'	=>	$pro_data[$i]["ProductName"]		
		));
	}
	 	
	$sql="select  m.*,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$memid;
	//echo $sql;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}		
	$mem_data=$db->sql_fetchrow($result);	
	if(!$mem_data["memID"]){
		redirect("index.php");
	}
	 $detail=html_entity_decode(nl2br($mem_data["aboutInfo"]));
			$arrStr=explode(' ',$detail);				
			$k= count($arrStr)<40 ? count($arrStr) :40;				
			$detail='';
		  for($j=0;$j<$k;$j++){
			   $detail.=$arrStr[$j].' ';
			 }
			  $comInfo= '<div align="justify" style="padding-left:10px; padding-right:10px">'.$detail  ;
			 if($k==40){
				 $comInfo.=" ...</div><div align=\"right\">
				  <img src=\"../images/arrow.gif\" border=\"0\"> <a href=\"supplier.php?supplier=".$memid."&mode=view\" 
				  class=\"lMenu\">More</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>";
			}else{
				$comInfo.='</div>';
			}	

	$memName= $mem_data["fName"] ."&nbsp;". $mem_data["lName"] ;
	
	$vn="<a href='http://my.yellowpages.vn/vn/supplier.php?supplier=".$cid."&ids=".$ids."&lang=vn' class=lMenu1> Vietnamese </a>" ; 
	$cn="<a href='http://my.yellowpages.vn/cn/supplier.php?supplier=".$cid."&ids=".$ids."&lang=cn' class=lMenu1> Chinese </a>" ; 
	$us="<a href='http://my.yellowpages.vn/supplier.php?supplier=".$cid."&ids=".$ids."&lang=us' class=lMenu1> English </a>" ; 
	
	$template->assign_vars(array(				
		'us' =>$us,
		'cn' =>$cn,	
		'vn' =>$vn, 
		'showlinklang' =>showlinklang(),
		'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\" align=\"absmiddle\">" : '' , 
		'companyName'	=>  $mem_data["CompanyName"],
		'maintitle'		=>$mem_data["CompanyName"] . ' - yellowpages.vn | Vietnam - ',
		'photo'		=>	!empty($mem_data["comImage"]) ? "<img src=\"barner/".$mem_data["comImage"]."\" >" : '' ,
		'info'		=>	$comInfo,
		'company'	=> $mem_data["CompanyName"],
		'ContactName'	=> ($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") .$memName,
		'Address'	=>$mem_data["Address"],
		'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
		'zipCode'	=>	$mem_data["Zip"],
		'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],		 
		'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
		'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
		'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
		'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
		'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		'mobiphone'	=>$mem_data["Mobile"],
		'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
		'Website'	=>$mem_data["Web"],
		'supp'	=>$memid,
		'fNoproduct'	=>$pro_count > 0 ? '' : 'style="display:none"' ,
		'url'	=>"supplier.php?&act=products&mode=main&supplier=".$memid
	));
	 
	$template->set_filenames(array(
		"body"	=> $template_body_page
	));
	$template->pparse('body');

}
function ViewDetail(){
	global $template_detail_page,$db,$template;
	$memid=isset($_GET["supplier"]) ? intval($_GET["supplier"]) : 0 ;
	
	$sql="select  m.*,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$memid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}		
	$mem_data=$db->sql_fetchrow($result);	
	if(!$mem_data["memID"]){
		redirect("index.php");
	}
	  
	$comInfo=strlen($mem_data["aboutInfo"])<250 ? html_entity_decode(nl2br($mem_data["aboutInfo"])) : html_entity_decode(nl2br($mem_data["aboutInfo"]));
 	$memName= $mem_data["fName"] ."&nbsp;". $mem_data["lName"] ;
	$template->assign_vars(array(			
		 
		'barner'	=>  "barner/".$mem_data["barner"],
		'supp'	=>$memid,
		'companyName'	=>  $mem_data["CompanyName"],
		'maintitle'		=> $mem_data["CompanyName"] . ' -  yellowpages.vn | Vietnam - ',
		'logo'	=>	!empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\" align=\"absmiddle\">" : '' ,
		'photo'		=>	!empty($mem_data["comImage"]) ? "<img src=\"barner/".$mem_data["comImage"]."\" align=\"right\" style=\"margin-left:10px;\">" : '' ,
		'cominfo'		=>	$comInfo,
		'company'	=> $mem_data["CompanyName"],
		'ContactName'	=> ($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") .$memName,
		
		'Address'	=>$mem_data["Address"],
		'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
		'zipCode'	=>	$mem_data["Zip"],
		'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
		'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
		
		'mobiphone'	=>$mem_data["Mobile"],
		'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
		
		'Website'	=>$mem_data["Web"],
		'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
		'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
		'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
		'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		
	));
 
	$template->set_filenames(array(
		"body"	=> $template_detail_page
	));
	$template->pparse('body');

}
function showlinklang(){
	global $template, $db, $site_base_href, $cid,$ids ;
	$memid=isset($_GET["supplier"]) ? intval($_GET["supplier"]) : 0 ;
	$sql ="select CompanyName,CompanyName_vn,CompanyName_cn from vb_memberprofile where memID=".$memid ;
	//echo $sql; die() ;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}		
	$mem_data=$db->sql_fetchrow($result);
	
	$vn="<a href=".$site_base_href."/vn/supplier.php?supplier=".$cid."&ids=".$ids."&lang=vn class=lMenu1> Tiếng Việt </a>" ; 
	$cn="<a href=".$site_base_href."/cn/supplier.php?supplier=".$cid."&ids=".$ids."&lang=cn class=lMenu1> &#20013;&#25991;&#29256; </a>" ; 
	$us="<a href=".$site_base_href."/supplier.php?supplier=".$cid."&ids=".$ids."&lang=us class=lMenu1> English </a>" ; 
	if( empty($mem_data["CompanyName_cn"]) or ($mem_data["CompanyName_cn"]=="NULL") ){
		$linklang = '<div><table>
					<tr>
						<td><a class="text-default">To Start select</a></td>
						<td><a class="text-default" ><img src="images/select.gif" width="17" height="18"></a></td>
						<td  class="lMenu1">    '.$vn.' | '.$us.' </td>
					</tr>
			</table></div>' ;
	}elseif(empty($mem_data["CompanyName"])or ($mem_data["CompanyName"]=="NULL") ){
		$linklang = '<div><table>
					<tr>
						<td><a class="text-default">To Start select</a></td>
						<td><a class="text-default" ><img src="images/select.gif" width="17" height="18"></a></td>
						<td  class="lMenu1">    '.$vn.' | '.$cn.' </td>
					</tr>
			</table></div>' ;
	}elseif(empty($mem_data["CompanyName_vn"]) or ($mem_data["CompanyName_vn"]=="NULL")){
		$linklang = '<div><table>
					<tr>
						<td><a class="text-default" >To Start select</a></td>
						<td><a class="text-default" ><img src="images/select.gif" width="17" height="18"></a></td>
						<td  class="lMenu1">   '.$us.'|'.$cn.' </td>
					</tr>
			</table></div>' ;
	}else{
		$linklang = '<div><table>
					<tr>
						<td><a class="text-default">To Start select</a></td>
						<td><a class="text-default" ><img src="images/select.gif" width="17" height="18"></a></td>
						<td  class="lMenu1"> '.$vn.' | '.$us.'|'.$cn.' </td>
					</tr>
			</table></div>' ;
	}
	return $linklang ;
}
 ?>